package com.macro.controller;


import com.macro.pojos.dto.*;
import com.macro.pojos.pojo.UiGoodsAttributeCategory;
import com.macro.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/api/v1/goods")
@Api(tags = "GoodsController", description = "商品管理")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    /**
     * 商品模糊分页查询
     * @param uiGoodsDto
     * @param userId
     * @return
     */
    @PostMapping("/queryGoods")
    @ApiOperation(value = "商品模糊分页查询",notes = "商品模糊分页查询")
    public ResponseResult queryGoods(@RequestBody UiGoodsDto uiGoodsDto, @RequestHeader Integer userId){
        return goodsService.queryGoods(uiGoodsDto);
    }

    /**
     * 商品批量操作
     * @param batchChangeDto
     * @param userId
     * @return
     */
    @PostMapping("/batchGoods")
    @ApiOperation(value = "商品批量操作",notes = "商品批量操作")
    public ResponseResult batchGoods(@RequestBody BatchChangeDto batchChangeDto, @RequestHeader Integer userId){
        return goodsService.batchGoods(batchChangeDto);
    }

    /**
     * 商品标签
     * @param labelChangeDto
     * @return
     */
    @PostMapping("/labelChange")
    @ApiOperation(value = "商品标签",notes = "商品标签")
    public ResponseResult labelChange(@RequestBody LabelChangeDto labelChangeDto, @RequestHeader Integer userId){
        return goodsService.labelChange(labelChangeDto);
    }

    /**
     * 添加商品
     *
     * @param userId
     * @param uiGoodsAddDto
     * @return
     */
    @PostMapping("/addGoods")
    @ApiOperation(value = "添加商品")
    public ResponseResult addGoods(@RequestHeader String userId, @RequestBody UiGoodsAddDto uiGoodsAddDto) {
        return goodsService.addGoods(uiGoodsAddDto);
    }

    /**
     * 根据id删除单个商品
     *
     * @param id
     * @return
     */
    @GetMapping("/delGoodsById")
    @ApiOperation(value = "根据id删除单个商品")
    public ResponseResult delGoodsById(@RequestHeader String userId, @RequestParam Integer id) {
        return goodsService.delGoodsById(id);
    }

    /**
     * 根据id更新单个商品信息
     *
     * @param userId
     * @param uiGoodsAddDto
     * @return
     */
    @PostMapping("/updateGoods")
    @ApiOperation(value = "根据id更新单个商品信息")
    public ResponseResult updateGoods(@RequestHeader Integer userId, @RequestBody UiGoodsAddDto uiGoodsAddDto) {
        return goodsService.updateGoods(uiGoodsAddDto);
    }

    /**
     * 画册上传
     *
     * @param file
     * @return
     */
    @PostMapping("/upLoad")
    public ResponseResult upload(@RequestHeader Integer userId, MultipartFile file) throws IOException {
        return goodsService.upload(file);
    }


    /**
     * 查询商品类别(添加第三步)
     *
     * @return
     */
    @PostMapping("/findGoodsType")
    public ResponseResult findGoodsType(@RequestHeader Integer userId, @RequestBody UiGoodsAttributeCategory uiGoodsAttributeCategory) {
        return goodsService.findGoodsType(uiGoodsAttributeCategory);
    }

    /**
     * 查询商品类别所对应的规格和参数(添加第三步)
     *
     * @return
     * @parm id
     */
    @GetMapping("/findAttributeAndParm")
    public ResponseResult findAttributeAndParm(@RequestHeader String userId,@RequestParam Integer id) {
        return goodsService.findAttributeAndParm(id);
    }

    /**
     * 查询所有专题
     * @param
     * @return
     */
    @PostMapping("/findAllSubject")
    public ResponseResult findAllSubject(@RequestHeader String userId, String subTitle) {
       return goodsService.findAllSubject(subTitle);
    }

    /**
     * 查询所有优选
     * @param userId
     * @param preferNname
     * @return
     */
    @PostMapping("/findAllPreference")
    public ResponseResult findAllPreference(@RequestHeader String userId,  String preferNname){
        return goodsService.findAllPreference(preferNname);
    }

}
